<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>英语教学系统</title>
    <link rel="stylesheet" href="static/css/common_form.css">
</head>
<body>
    <header>
        <div class="header-line"></div>
    </header>
    <div class="content">
        <img class="content-logo" src="static/img/form_logo.png" alt="logo">
        <h1 class="content-title">英语教学系统登录</h1>
        <div class="content-form">
                <div id="change_margin_1">
                    <input class="user" id="user" type="text" name="user" placeholder="请输入用户名"/>
                </div>
                <!-- input的value为空时弹出提醒 -->
                <p id="remind_1"></p>
                <div id="change_margin_2">
                    <input class="password" id="password" type="password" name="password" placeholder="请输入密码" >
                </div>
                <!-- input的value为空时弹出提醒 -->
                <p id="remind_2"></p>
                <div id="change_margin_3">
                    <input id="login1" class="content-form-signup" type="button" value="登录">
                </div>
        </div>
        <div class="content-login-description">没有账户？</div>
        <div><a class="content-login-link" href="register.html">注册</a></div>
<script src="static/js/jquery-2.2.3.js"></script>
<script>
$(function() {
	$("#login1").click(function(){
		login();
	});
});

function login(){
	var data ={"userName":$("#user").val(),"password":$("#password").val()};
	$.ajax({
		url : "user/login",//请求的url
		type : "post",//请求方式
		data : JSON.stringify(data),
		dataType : "json",//后台数据返回类型
		contentType : "application/json",
		success : function(data) {//响应成功执行的方法
            console.log(data)
			if (data.status=="SUCCESS") {
				if (data.rows.userType=="1") {
					window.location.href='t_course.html';
				} else {
					window.location.href='course.html';
				}
			} else {
				alert("用户名或者密码不正确");
			}
		},
		error : function() {//出现异常执行方法
			alert("出现异常啦...");
		}
	});
}

</script>
</body>
</html>